From 437268370661087dbe31323efb18dfe1a518da33 Mon Sep 17 00:00:00 2001
From: flu0r1ne <flu0r1ne@flu0r1ne.net>
Date: Wed, 21 Jul 2021 03:59:15 -0500
Subject: Dynamic markdown page generation with preloading

---
 pages/logs/[directory].tsx | 58 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100644 pages/logs/[directory].tsx

(limited to 'pages/logs/[directory].tsx')

diff --git a/pages/logs/[directory].tsx b/pages/logs/[directory].tsx
new file mode 100644
index 0000000..00fe78d
--- /dev/null
+++ b/pages/logs/[directory].tsx
@@ -0,0 +1,58 @@
+import path from 'path';
+import { GetStaticProps, GetStaticPropsContext } from 'next';
+import React, { FC } from 'react';
+import { getPosts, getMarkdown, Post, getPostFromDirectory } from '../../utils/Posts';
+import Markdown from '../../components/Markdown';
+import DefaultPage from '../../templates/Default';
+
+interface Props {
+  post: Post;
+  markdown: string;
+}
+
+const Page : FC<Props> = ({ post, markdown }) => {
+    return (
+      <>
+        <DefaultPage
+          path={"/logs/" + post.directory}
+        >
+        <Markdown
+          md={markdown}
+        />
+        </DefaultPage>
+      </>
+    );
+}
+
+export default Page;
+
+export const getStaticProps: GetStaticProps = async (
+    context: GetStaticPropsContext
+  ) => {
+    const directory = context.params!.directory as string;
+
+    const post = await getPostFromDirectory(directory);
+
+    const markdown = await getMarkdown(post);
+    
+    return {
+      props: { post, markdown },
+    }
+}
+
+export async function getStaticPaths() {
+  const posts = await getPosts();
+
+  const paths = posts.map((post) => {
+    return {
+      params: {
+        directory: post.directory
+      }
+    };
+  });
+
+  return {
+    paths,
+    fallback: false
+  };
+}
\ No newline at end of file
-- 
cgit v1.2.3

